/**
 * 功能描述 餐饮落实
 */

define(function (require, exports, module) {
	var Dialog = require("dialog");
	var EditGrid = require("editgrid");
    var instance = {
        initComponent: function (widget) {
        	var dinnergrid = new EditGrid({
        		id:"dinnerdinnergrid",
        		parentNode:"#checkInDinner",
        		
        		model:{
        			head:{
        				items:[{
        					id:"add",
            				text:"选择",
            				type:"button"
        				}],
        			},
        			onAdd:function(editors){
        				var dinnerSort = editors["dinnerSort"];
        				var dinnerDate = editors["dinnerDate"];
        				var perNumber = editors["perNumber"];
        				var level = editors["level"];
        				var dinnerAddress = editors["dinnerAddress"];
        				var taste = editors["taste"];
        				var preference = editors["preference"];
        				var species = editors["species"];
        				var drinks = editors["drinks"];
        				var descript = editors["descript"];
        				
        				if(dinnerSort.getValue() == "" || dinnerDate.getValue() == ""){
							return false;
						}else{
	        				dinnergrid.add({
	        					dinnerSort : dinnerSort.getValue(),
	        					dinnerDate : dinnerDate.getValue(),
	        					perNumber : perNumber.getValue(),
	        					level : level.getValue(),
	        					dinnerAddress : dinnerAddress.getValue(),
	        					taste : taste.getValue(),
	        					preference : preference.getValue(),
	        					species : species.getValue(),
	        					drinks : drinks.getValue(),
	        					descript : descript.getValue()
	        				})
	        				var option=[];
	        				var dinnerData= dinnergrid.getData();
	        				for ( var i=0; i< dinnerData.length;i++) {
	        					
								if(dinnerData[i].dinnerSort=="Breakfast"){
									option=[{key:"Lunch",value:"午餐"},{key:"Supper",value:"晚餐"}]
								}else{
									if(dinnerData[i-1].dinnerSort=="Breakfast" && dinnerData[i].dinnerSort=="Lunch"){
										option=[{key:"Supper",value:"晚餐"}]
									}
								} 
								
							}
	        				editors["dinnerSort"].setData(option)
						}
        			},
        			columns:[{
        				name:"dinnerSort",
        				label:"餐饮类别",
        				format: function (value, row) {
        					if(value.key==null){
        						if(value=="Breakfast"){
            						return "早餐";
            					} else if(value=="Lunch"){
            						return "午餐";
            					}else if(value=="Supper"){
            						 return "晚餐";
            					}
        					}else{
        						if(value.key=="Breakfast"){
            						return "早餐";
            					} else if(value.key=="Lunch"){
            						return "午餐";
            					}else if(value.key=="Supper"){
            						 return "晚餐";
            					}
        					}
        					
        	             },
        				editor:{
							type:"select",
							placeholder: "输入早餐\午餐\晚餐",
							options:[{
								key:"Breakfast",
								value:"早餐"
							},{
								key:"Lunch",
								value:"午餐"
							},{
								key:"Supper",
								value:"晚餐"
							}],
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.dinnerSort);
							},
							onChange:function(plugin,index,rowData){
								rowData.dinnerSort = {
										key:plugin.getValue(),
										value:plugin.getText()
								};
								dinnergrid.update(index,rowData);
							}
						}
        			},{
        				name:"dinnerDate",
        				label:"用餐时间",
        				//format:"date",
						/*formatparams:{
							mode:"HH:mm"
						},*/
						editor:{
							type:"date",
							mode: "HH:mm",
							//minDate: "",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.dinnerDate);
							},
							onChange:function(plugin,index,rowData){
								
								rowData.dinnerDate = plugin.getValue();
								dinnergrid.update(index,rowData);
								
							}
						}
        			},{
        				name:"perNumber",
        				label:"人数",
        				editor:{
							type:"text",
							placeholder: "请输入人数",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.perNumber);
							},
							onChange:function(plugin,index,rowData){
								rowData.perNumber = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						}
        			},{
        				name:"level",
        				label:"标准",
        				editor:{
							type:"text",
							placeholder: "请输入标准",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.level);
							},
							onChange:function(plugin,index,rowData){
								rowData.level = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						}
        			},{
        				name:"dinnerAddress",
        				label:"用餐地点",
        				editor:{
        					type:"text",
							placeholder: "请输入用餐地点",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.dinnerAddress);
							},
							onChange:function(plugin,index,rowData){
								rowData.dinnerAddress = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						},
        			},{
        				name:"taste",
        				label:"口味(客源地)",
        				editor:{
							type:"text",
							placeholder: "请输入口味(客源地)",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.taste);
							},
							onChange:function(plugin,index,rowData){
								rowData.taste = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						}
        			},{
        				name:"preference",
        				label:"餐位偏好及保留时间",
        				editor:{
							type:"text",
							placeholder: "请输入餐位偏好",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.preference);
							},
							onChange:function(plugin,index,rowData){
								rowData.preference = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						}
        			},{
        				name:"species",
        				label:"指定菜",
        				editor:{
							type:"text",
							placeholder: "请输入指定菜",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.species);
							},
							onChange:function(plugin,index,rowData){
								rowData.species = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						}
        			},{
        				name:"drinks",
        				label:"酒水饮料",
        				editor:{
							type:"text",
							placeholder: "请输入酒水饮料",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.drinks);
							},
							onChange:function(plugin,index,rowData){
								rowData.drinks = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						}
        			},{
        				name:"descript",
        				label:"备注",
        				editor:{
							type:"text",
							placeholder: "请输入备注",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.descript);
							},
							onChange:function(plugin,index,rowData){
								rowData.descript = plugin.getValue();
								dinnergrid.update(index,rowData);
							}
						}
        			}]
        		}
        	});
        	widget.set("ciidinnergrid",dinnergrid);
        }
    };
    module.exports = instance;
});
